﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Model;
using DAL;

public partial class Teacher_TeacMasterPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnAddQuestion_Click(object sender, EventArgs e)
    {
        string _questionstyle = questionStyle.Text;
        string _title = thetitle.Text;
        int _score = int.Parse(score.Text);
        string _hardLevel = hardLevel.Text;
        string _answer=answer.Text;
        string _analysis = analysis.Text;
        /*
         fillinblanks">填空题</asp:ListItem>
        <asp:ListItem Value="exclusivechoices">单选题</asp:ListItem>
        <asp:ListItem Value="multiplechoices">多选题</asp:ListItem>
        <asp:ListItem Value="shortanswers"
         
         */

        switch (_questionstyle)
        {
            case "null":
                msg.Text = "请选择题目类型！";
                break;
            case "fillinblanks":
                FillinBlank fillinblank = new FillinBlank();
                fillinblank.id = Guid.NewGuid().ToString();
                fillinblank.title = _title;
                fillinblank.answer = _answer;
                fillinblank.score = _score;
                fillinblank.hardLevel = _hardLevel;
                fillinblank.teacherId = (string)Session["id"];
                fillinblank.date = DateTime.Now.ToLocalTime();
                fillinblank.analysis = _analysis;

                FillinBlankManager fillInBlankManager = new FillinBlankManager();

                try
                {
                    fillInBlankManager.Add(fillinblank);
                    msg.Text = "添加成功！";
                }
                catch (Exception fillInBlankException)
                {
                    msg.Text = "添加失败！";
                }
                break;
            case "exclusivechoices":
                ExclusiveChoice exclusivechoice = new ExclusiveChoice();
                exclusivechoice.id = Guid.NewGuid().ToString();
                exclusivechoice.title = _title;
                exclusivechoice.answer = _answer;
                exclusivechoice.score = _score;
                exclusivechoice.hardLevel = _hardLevel;
                exclusivechoice.teacherId = (string)Session["id"];
                exclusivechoice.date = DateTime.Now.ToLocalTime();
                exclusivechoice.analysis = _analysis;
                exclusivechoice.choiceA = choiceA.Text;
                exclusivechoice.choiceB = choiceB.Text;
                exclusivechoice.choiceC = choiceC.Text;
                exclusivechoice.choiceD = choiceD.Text;
                ExclusivechoiceManager exclusivechoiceManager = new ExclusivechoiceManager();
                try
                {
                    exclusivechoiceManager.Add(exclusivechoice);
                    msg.Text = "添加成功！";
                }
                catch (Exception exclusivechoiceException)
                {
                    msg.Text = "添加失败！";
                }
                break;
            case "multiplechoices":
                MultipleChoice multipleChoice = new MultipleChoice();
                multipleChoice.id = Guid.NewGuid().ToString();
                multipleChoice.title = _title;
                multipleChoice.answer = _answer;
                multipleChoice.score = _score;
                multipleChoice.hardLevel = _hardLevel;
                multipleChoice.teacherId = (string)Session["id"];
                multipleChoice.date = DateTime.Now.ToLocalTime();
                multipleChoice.analysis = _analysis;
                multipleChoice.choiceA = choiceA.Text;
                multipleChoice.choiceB = choiceB.Text;
                multipleChoice.choiceC = choiceC.Text;
                multipleChoice.choiceD = choiceD.Text;
                multipleChoice.choiceE = choiceE.Text;
                multipleChoice.choiceF = choiceF.Text;
                MultiplechoiceManager multipleChoiceManager = new MultiplechoiceManager();
                try
                {
                    multipleChoiceManager.Add(multipleChoice);
                    msg.Text = "添加成功！";
                }
                catch (Exception multipleChoiceException)
                {
                    msg.Text = "添加失败！";
                }
                break;
            case "shortanswers":
                ShortAnswer shortAnswer = new ShortAnswer();
                shortAnswer.id = Guid.NewGuid().ToString();
                shortAnswer.title = _title;
                shortAnswer.answer = _answer;
                shortAnswer.score = _score;
                shortAnswer.hardLevel = _hardLevel;
                shortAnswer.teacherId = (string)Session["id"];
                shortAnswer.date = DateTime.Now.ToLocalTime();
                shortAnswer.analysis = _analysis;

                ShortanswerManager shortAnswerManager = new ShortanswerManager();
                try
                {
                    shortAnswerManager.Add(shortAnswer);
                    msg.Text = "添加成功！";
                }
                catch (Exception shortAnswerException)
                {
                    msg.Text = "添加失败！";
                }
                break;
        }
    }

}
